package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mappers.QuestionMapper;
import com.tanhua.model.domain.Question;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class QuestionApiImpl implements QuestionApi {

    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public Question findById(Long userId) {
        LambdaQueryWrapper<Question> lqw =new LambdaQueryWrapper<>();
        lqw.eq(Question::getUserId,userId);
         return questionMapper.selectOne(lqw);
    }

    @Override
    public void save(Question question) {
        questionMapper.insert(question);
    }

    @Override
    public void update(Question question) {
        questionMapper.updateById(question);
    }

    @Override
    public String findByTxT(Long userId) {
        LambdaQueryWrapper<Question> lqw =new LambdaQueryWrapper<>();
        lqw.eq(Question::getUserId,userId);
        Question question = questionMapper.selectOne(lqw);
        if(question==null){
            return "你喜欢apex吗";
        }
        return question.getTxt();
    }
}